#include <stdio.h>
#include <unistd.h>
#include <sched.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <sys/ioctl.h>
#include <sys/syscall.h>

#include "my_common.h"

#define MY_DEV "/dev/mydev"

int main(int argc, char *argv[])
{
	int fd;
	unsigned int cmd;
	int ret;

	if (argc != 2) {
		printf("Usage: myapp <cmd>\n");
		printf("\t cmd:1~3\n");
		return -1;
	}

	ret = atoi(argv[1]);
	if (ret < 1 || ret > 3) {
		printf("cmd must be in range 1~3\n");
		return -1;
	}

	switch(ret) {
	case 1:
		cmd = CMD1;
		break;
	case 2:
		cmd = CMD2;
		break;
	case 3:
		cmd = CMD3;
		break;
	default:
		printf("Unsupported cmd");
		return -1;
	}

	fd = open(MY_DEV, O_RDWR);
	if (fd < 0) {
		printf("open %s failed, errno=%d\n", MY_DEV, fd);
		return -1;
	}

	ret = ioctl(fd, cmd);
	if (ret < 0) {
		printf("ioctl: cmd %d failed, errno=%d\n", cmd, ret);
	}

	close(fd);

	return 0;
}
